package com.app.fenak;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ViewSwitcher;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class DrawPathActivity extends MapActivity {

	private boolean isCustomBack;
	private MapView mapView;
	private MapController controller;
	private ViewSwitcher switcher;
	private View nextBtn;
	@Override
	protected void onCreate(Bundle icicle) { 
		super.onCreate(icicle);
		setContentView(R.layout.draw_path_view);
		
		mapView = (MapView) findViewById(R.id.draw_path_map);
        mapView.setBuiltInZoomControls(true);
        controller = mapView.getController();
        // Stub Code to test only
        mapView.setStreetView(true);
        mapView.invalidate();
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
        FenakItemizedOverlay itemizedoverlay = new FenakItemizedOverlay(drawable);
        
        GeoPoint point = new GeoPoint( (int) (30.052648 * 1E6) , (int) (31.207028 * 1E6));
        itemizedoverlay.addOverlay((new OverlayItem(point, "Location ", "Location")));
        
        controller.animateTo(point);
        
        mapOverlays.add(itemizedoverlay);
        mapView.invalidate();
		
		switcher = (ViewSwitcher) findViewById(R.id.switcher);
		nextBtn = findViewById(R.id.next_btn);
		nextBtn.setVisibility(View.VISIBLE);
		nextBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				switcher.showNext();
				isCustomBack = true;
			}
		});
	}
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public void onBackPressed() {
		if(isCustomBack) { 
			switcher.showPrevious();
			isCustomBack = false;
		}
		else 
			super.onBackPressed();
	}

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		
		super.onWindowFocusChanged(hasFocus);
		while(controller.zoomIn()) {
        	controller.zoomIn();
        }
        controller.zoomOut();
        controller.zoomOut();
	}
}
